function dialogForm() {}

dialogForm.prototype = {
	oForm : null,
	objectId : null,
	submitTitle : 'Отправить',
	uri : null,
	submitUri : null,
	success : function() {},
	h1 : null,
	
	show : function() {
		var __self = this;
		
		if (this.uri === null) {
			alert('Не задан URI');
			return;
		}
		
		this.oForm = $('<form></form>')
			.attr('id', 'myform');
		
		var oTable = $('<table></table>')
			.attr('class', 'dialog_form')
			.attr('cellspacing', '10')
			.attr('cellpadding', '0')
			.attr('id','mytableform');
		
		var oTdLoader = $('<td></td>')
			.html('<img src="'+baseURI+'/images/admin/ajax-loader.gif" />')
			.css({textAlign:'center'});
		
		oTable.append($('<tr></tr>').attr('id','mytableloader').append(oTdLoader));
		
		$.ajax({
			url: this.uri,
			dataType: 'xml',
			type: 'get',
			error: function() { alert ('Невозможно загрузить форму по адресу:\n' + this.uri)  },
			success: function(xml) {				
				$('#mytableloader').remove();
				
				var form = $(xml).find('form');
				
				__self.objectId = form.attr('prefix');
				var objectId = __self.objectId;
				
				$(form).find('field').each(function() {					
					var fieldId = $(this).attr('id');
					var fieldName = $(this).attr('name');
					var fieldCharacter = $(this).attr('character');
					
					var oTr = $('<tr></tr>');
															
					oTr.append(
						$('<td></td>')
							.attr('class', 'field_label')
							.text($(this).find('title').text()+':')
					);
					
					var oInput = $('<input>')
						.attr('type', 'text')
						.attr('value', $(this).find('value').text())
						.attr('id', 'field_'+fieldId)
						.attr('name', 'data['+objectId+']['+fieldName+']');
					
					var oDivError = $('<div></div>')
						.attr('id', 'error_'+fieldName)
						.attr('class', 'error')
						.css({display:'none'});
					
					oTr.append(
						$('<td></td>')
							.attr('class', 'field_value')
							.append(oInput)
							.append(oDivError)
						);
					
					$('#mytableform').append(oTr);
					updateDialogPosition ();
				});
			}
		});
		
		if (this.h1 !== null) {
			this.oForm.append($('<h1></h1>').text(this.h1));
		}
		
		this.oForm.append(oTable);
			
		var oSubmit = $('<input>')
			.attr('type', 'submit')
			.attr('value', this.submitTitle);
			
		this.oForm.append($('<p></p>').append(oSubmit));
		
		showDialog($('<div></div>').append(this.oForm));
	},
	
	get : function() {
		return this.oForm;
	},
	
	submit : function() {
		var __self = this;
		
		if (this.submitUri === null || this.submitUri == undefined || typeof this.submitUri == 'undefined') {
			alert('Не определен URI валидации формы!');
			return false;
		}
		
		var requestData = new Array();
				
		$('#myform :input').each(function() {
			if ($(this).attr('name') != '') {
				requestData.push($(this).attr('name')+'='+$(this).val());
			}
		});
		
		requestData = requestData.join('&');
		
		$.ajax({
			url: this.submitUri,
			data: requestData,
			dataType: 'xml',
			type: 'post',
			cache: false,
			error: function() { alert ('Ошибка валидации формы по адресу:\n' + __self.submitUri)  },
			success: function(xml) {
				var status = $(xml).find('status').find('value').text();
				
				if (status == 1) {
					__self.success();
				} else {
					$(xml).find('errors').find('field').each(function() {
						$('#error_'+$(this).attr('name')).text($(this).text()).show();
					});
				}
			}
		});
		
		return false;
	}
}